void Add_New_Class()
{
	int i; char key;
	do
	{
		printf("\n Add New Class ");
		printf("\n (* Infomation Required *)");
		printf("\n -------------------------------");

lbl:  	printf("\n   Class Name(*): ");	fflush(stdin);  gets(cls[ccount].classname);

		if (isClassname(cls[ccount].classname)==0)
	 	{
	 		printf("\n Ten lop khong hop le");	goto lbl;
	 	}
		else
		{
			strUpper(cls[ccount].classname);
		}

		printf("\n Head Teacher(*): ");	fflush(stdin);	gets(cls[ccount].teacher);
		printf("\n         Room No: ");	fflush(stdin);	gets(cls[ccount].room);
		printf("\n       Time Slot: ");	fflush(stdin);	gets(cls[ccount].time);

		do
		{
      	printf("\n  Student Number: "); scanf("%d",&i);
		}	while(!((i >= 16)&&(i<=30)));

		cls[ccount].total=i;
		ccount++;

		printf("\n-------------------------- ");
		printf("\n Do you want to save (y/n): ");	fflush(stdin); scanf("%c",&key); if (key=='n')	ccount--;
		printf("\n Do you want to continue (y/n):");fflush(stdin); scanf("%c",&key);
	} while(key!='n');
}

void Edit_Class_Infomation()
{
	int i; char key; int exits;
	char clsname[10]; struct_class classTemp;

	do {
		printf("\n Edit Class Infomation ");
		printf("\n------------------------- ");		
		printf("\n Input Class Name: "); fflush(stdin); gets(clsname);
		exits = 0;
		for(i=0;i<ccount;i++)
		{
			if (strcmp(cls[i].classname,clsname)==0)
			{

				printf("\n  Class Name(*): %s",cls[i].classname);
			 	printf("\n   Head Teacher: %s",cls[i].teacher);
				printf("\n        Room No: %s",cls[i].room);
				printf("\n      Time Slot: %s",cls[i].time);
				printf("\n Student Number: %d",cls[i].total);
				printf("\n------------------------- ");
				exits = 1;
				fflush(stdin);

				printf("\n Input Class Name(*): ");	gets(classTemp.classname);
				printf("\n  Input Head Teacher: "); gets(classTemp.teacher);
				printf("\n       Input Room No: "); gets(classTemp.room);
				printf("\n     Input Time Slot: "); gets(classTemp.time);
				printf("\n      Student Number: "); scanf("%d",&classTemp.total);

				printf("\n Do you want to save (y/n): "); fflush(stdin); scanf("%c",&key);
				if (key=='y')
				{
					cls[i] = classTemp;					
				}
				printf("\n  Class Name(*): %s",cls[i].classname);
				printf("\n   Head Teacher: %s",cls[i].teacher);
				printf("\n        Room No: %s",cls[i].room);
				printf("\n      Time Slot: %s",cls[i].time);
				printf("\n Student Number: %d",cls[i].total);
			}

		}
			if(exits==0) printf("\n Class Name dont exit!"); 			
			printf("\n Do you want to continue (y/n):");fflush(stdin); scanf("%c",&key);			
	} while(key!='n');
}

void Delete_Class_Infomation()
{
	int i,j; char key; int exits;
	char clsname[10];
	
	do 
	{
		printf("\n Delete Class Information");
		printf("\n------------------------- ");		
		printf("\n Input ClassName: ");	fflush(stdin); gets(clsname);
		exits=0;
		for(i=0;i<ccount;i++)
		{
			if (strcmp(cls[i].classname,clsname)==0)
			{
				exits=1;
				printf("\n------------------------- ");
				printf("\n   ClassName(*): %s",cls[i].classname);
				printf("\n   Head Teacher: %s",cls[i].teacher);
				printf("\n        Room No: %s",cls[i].room);
				printf("\n      Time Slot: %s",cls[i].time);
				printf("\n Student Number: %d",cls[i].total);
				printf("\n------------------------- ");				

				printf("\n Do you want to delete (y/n): "); fflush(stdin); scanf("%c",&key);
				if (key=='y')
				{
					for(j=i-1;j<ccount;j++)
					{
						strcpy(cls[j].classname,cls[j+1].classname);
						strcpy(cls[j].teacher,cls[j+1].teacher);
						strcpy(cls[j].room,cls[j+1].room);
						strcpy(cls[j].time,cls[j+1].time);
						cls[j].total=cls[j+1].total;
					}
					ccount--;
				}
			}
		}
	   if (exits==0) printf("Class name does not exits !");
	   printf("\n Do you want to continue (y/n):");fflush(stdin); scanf("%c",&key);			
	} while(key!='n');
}

void ClassList()
{
	int i=0;	
	
	for(i=0;i<ccount;i++)
	{
		if (i%10==0)
		{
			system("cls");
			printf("\n Class List ");
			printf("\n--------------------------------------------------------------------------- ");
			printf("\n %-10s %-30s %-10s %-10s","Class Name","Header Teacher","Room No","Time Slot");
			printf("\n--------------------------------------------------------------------------- ");
			printf("\n %-10s %-30s %-10s %-10s",cls[i].classname,cls[i].teacher,cls[i].room,cls[i].time);
		}

		if ((i+1)%10==0)
		{
			printf("\n Press any key to display more information...");
			getch();
			continue;
		}
	}
	printf("\n---------------------------------------------------------------------------");
	getch();

}

void info_class()
{
	int key=0;
		do
		{
      	system("cls");
			printf("\n Class Information");
			printf("\n ------------------------------");
			printf("\n 1. Add New Class");
			printf("\n 2. Edit Class Infomation");
			printf("\n 3. Delete Class Infomation");
			printf("\n 4. Class List");
			printf("\n 5. Back to Main Menu");
			printf("\n 6. Exit");
			printf("\n ------------------------------");
			printf("\n Select the option(1-6): ");
			scanf("\n %d",&key);

			switch(key)
			{
				fflush(stdin);
				case 1:Add_New_Class();
            	break;
				case 2:Edit_Class_Infomation();
					break;
				case 3:Delete_Class_Infomation();
					break;
				case 4:ClassList();
					break;
				case 5:MainMenu();
					break;
            case 6:quit();
            	break;
				default:	printf("\n Selection the option(1-6) ");
			}
		}while(key!=6);
	getch();	
} 
